package com.example.store;

import com.example.store.entity.User;
import com.example.store.mapper.UserMapper;
import com.example.store.service.IUserService;
import com.example.store.service.ex.ServiceException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Date;

@RunWith(SpringRunner.class)
@SpringBootTest
public class userMapperTestCase {

	@Autowired
	public UserMapper mapper;

	@Test
	public void insert() {
		User user = new User();
		user.setUsername("root11");
		user.setPassword("1234");
		Integer rows = mapper.insert(user);
		System.err.println("rows=" + rows);
	}

	@Test
	public void findByUsername() {
		String username = "root";
		User result = mapper.findByUsername(username);
		System.err.println(result);
	}

	@Autowired
	public IUserService service;

	@Test
	public void reg() {
		try {
			User user = new User();
			user.setUsername("mybatis");
			user.setPassword("1234");
			user.setGender(1);
			user.setPhone("13800138006");
			user.setEmail("mybatis@tedu.cn");
			user.setAvatar("http://www.tedu.cn/mybatis.png");
//			service.reg(user);
			System.err.println("OK");
		} catch (ServiceException e) {
			System.err.println(e.getClass().getName());
			System.err.println(e.getMessage());
		}
	}



	@Test
	public void login() {
		try {
			String username = "root";
			String password = "1234";
			User data = service.login(username, password);
			System.err.println(data);
			System.out.println ("登陆成功");
		} catch (ServiceException e) {
			System.err.println(e.getClass().getName());
			System.err.println(e.getMessage());

		}
	}


	@Test
	public void updateInfo() {
		User user = new User();
		user.setUid(20);
		user.setGender(0);
		user.setPhone("13100131001");
		user.setEmail("root@tedu.cn");
		user.setModifiedUser("超级管理员");
		user.setModifiedTime(new Date ());
		Integer rows = mapper.updateInfo(user);
		System.err.println("rows=" + rows);
	}


}
